package Demo;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class java4 {
	public static void main(String[] args) throws IOException {
		File src = new File("D:\\aaa\\src");
		File dest = new File("aaa\\dest");
		copy(src, dest);
	}

	private static void copy(File src, File dest) throws IOException {
		if (src.isDirectory()) {
			if (!dest.exists()) {
				dest.mkdirs();
			}
			String[] files = src.list();
			if (files != null) {
				for (String file : files) {
					File srcFile = new File(src, file);
					File destFile = new File(dest, file);
					copy(srcFile, destFile);
				}
			}
		} else {
			FileReader fr=new FileReader(src);
			FileWriter fw=new FileWriter(dest);
			char[] c=new char[1024];
			while(fr.read(c)!=-1){
				fw.write(c);
				fw.flush();
			}
			fr.close();
			fw.close();
		}
	}
}

